<?php
/**
 * User Class
 */
class User extends CI_Controller {
	/**
	 * Constructor, load Semester_model, Cabang_model
	 */
	function User()
	{
		parent::__construct();
		$this->load->model('user_model', '', TRUE);
		$this->load->model('Home_model', '', TRUE);
		$this->load->model('role_model', '', TRUE);
	}
	
	/**
	 * Iid_userialisasi variabel untuk $title(untuk id element <body>), dan */
	var $title = 'User';
	
	/**
	 * Memeriksa user state,
	 * jika tidak akan meredirect ke halaman login
	 */
	function index()
	{
		//cek nih user udah login apa blom, kalo blom lempar ke halaman login
		if ($this->session->userdata('login') == FALSE)
		{
			redirect('auth');
		}
		$id_role = $this->session->userdata('id_role'); 
		$data['hak_akses0'] = $this->Home_model->get_hak_akses($id_role,0);
		$data['hak_akses1'] = $this->Home_model->get_hak_akses($id_role,1);
		$data['hak_akses2'] = $this->Home_model->get_hak_akses($id_role,2);
		
		// Load default view
		$data['title'] = $this->title;
		$data['main_view'] = 'user/user_view';
		$data['all_role'] = $this->role_model->get_all_role();
		$data['all_user'] = $this->user_model->get_all_user();
		// Load view
		$this->load->view('template', $data);
	}
	
	function add_user(){
		$data_user = array(
				'NAMA' 		=> $this->input->post('nama_user'),
				'USERNAME' 	=> $this->input->post('username'),
				'PASSWORD' 	=> md5($this->input->post('password')),
				'EMAIL' 	=> $this->input->post('email'),
				'ID_ROLE' 	=> $this->input->post('id_role')
			);
		$this->user_model->insert_user($data_user);
		
	}
	
	function delete_user($id_user){
		$id_user = $this->input->post('id_user');
		$this->user_model->delete_user($id_user);
	}
	
	function update_user(){
		$id_user = $this->input->post('id_user');
		$data_user = array(
			'NAMA'		=> $this->input->post('nama_user'),
			'USERNAME'	=> $this->input->post('username'),
			'EMAIL'		=> $this->input->post('email'),
			'ID_ROLE' 	=> $this->input->post('id_role')
		);
		$this->user_model->update_user($id_user, $data_user);
	}
	
}
// END User Class

/* End of file user.php */
/* Location: ./system/application/controllers/user.php */